## 状态机
class_name StateMachineNode extends Node

## 默认状态
@export var current_state: StateBase
## 上个状态
var last_state : String = ""

func _ready() -> void:
	await get_parent().ready
	current_state.enter()


func _process(delta: float) -> void:
	current_state.process_update(delta)


func _physics_process(delta: float) -> void:
	current_state.physics_process_update(delta)


func change_state(target_state_name: String) -> void:
	var target_state_node : StateBase = get_node_or_null(target_state_name)
	if target_state_node == null:
		printerr("状态机：状态不存在")
		return
	
	last_state = current_state.name
	current_state.exit()
	current_state = target_state_node
	current_state.enter()
